package com.szbmyoubao.app.ui.preview

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import com.szbmyoubao.app.view.dialog.DownLoadImageDialog
import com.bumptech.glide.Glide
import com.ellecity06.common.base.BaseMvvmFragment
import com.ellecity06.common.base.BaseViewModel
import com.ellecity06.cwhiskymall.databinding.FragmentPreviewImageBinding

/**
 * @author ellecity06
 * @time 2025/3/16 18:54
 * @des
 */
class PreviewImageFragment : BaseMvvmFragment<FragmentPreviewImageBinding, BaseViewModel>() {
    private val imageUrl: String? by lazy { arguments?.getString(URL) }

    companion object {
        private const val URL = "key_url"

        @JvmStatic
        fun newInstance(url: String): PreviewImageFragment {
            val fragment = PreviewImageFragment()
            val bundle = Bundle().apply {
                putString(URL, url)
            }
            fragment.arguments = bundle
            return fragment
        }

    }

    override fun lazyInit() {
        binding.ivDownload.setOnClickListener {
            imageUrl?.let {
                DownLoadImageDialog(requireActivity(), mutableListOf(it)).show()
            }

        }
        Glide.with(requireActivity())
            .load(imageUrl)
            .into(binding.ivImage)
    }

    override fun inflateBinding(
        inflater: LayoutInflater,
        container: ViewGroup?
    ): FragmentPreviewImageBinding {
        return FragmentPreviewImageBinding.inflate(inflater, container, false)
    }
}
